package contest.sweek200;

/**
 * LeetCode1537. 最大得分
 * @author code_yc
 * @version 1.0
 * @date 2020/8/3 22:38
 */
public class Solution4 {

    // 双指针
    public int maxSum(int[] nums1, int[] nums2) {
        long mod = 1000000007;
        long max1 = 0;
        long max2 = 0;
        int i = 0;
        int j = 0;
        while (i < nums1.length && j < nums2.length) {
            if (nums1[i] == nums2[j]) {
                long cur = Math.max(max1, max2) + nums1[i];
                i++;
                j++;
                max1 = max2 = cur;
            } else if (nums1[i] < nums2[j]) {
                max1 += nums1[i++];
            } else {
                max2 += nums2[j++];
            }
        }
        while (i < nums1.length) {
            max1 += nums1[i++];
        }
        while (j < nums2.length) {
            max2 += nums2[j++];
        }
        return (int) (Math.max(max1, max2) % mod);
    }
}
